package com.fudan.framework.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.List;

import com.fudan.sys.entity.Permission;


public class PermissionUtils {

	public static void main(String[] args) throws Exception {
		Connection connection = DriverManager.getConnection("jdbc:mysql:///ailiuyi", "root", "123456");
		List<Permission> list = buildPermissions();
		for (Permission permission : list) {
			PreparedStatement statement = connection.prepareStatement("insert into t_permission(id,name,code,pid) values (?,?,?,?)");
			statement.setInt(1, permission.getId());
			statement.setString(2, permission.getTitle());
			statement.setString(3, permission.getCode());
			statement.setInt(4, permission.getParentId());
			statement.execute();
			statement.close();
		}
		connection.close();
	}
	private static List<Permission> buildPermissions() {
		List<Permission> pl = new ArrayList<Permission>();
		
		pl.add(p(1,"权限设置","sys:permission",0));
		pl.add(p(2,"查看权限列表","sys:permission:view",1));
		
		pl.add(p(3,"角色设置","sys:role",0));
		pl.add(p(4,"查看角色列表","sys:role:view",3));
		pl.add(p(5,"添加角色","sys:role:add",3));
		pl.add(p(6,"修改角色","sys:role:mod",3));
		pl.add(p(7,"删除角色","sys:role:del",3));
		
		pl.add(p(8,"用户设置","sys:user",0));
		pl.add(p(9,"查看用户列表","sys:user:view",8));
		pl.add(p(10,"添加用户","sys:user:add",8));
		pl.add(p(11,"修改用户","sys:user:mod",8));
		pl.add(p(12,"删除用户","sys:user:del",8));
		
		pl.add(p(13,"售后单","biz:sale",0));
		pl.add(p(14,"查看售后单","biz:sale:view",13));
		pl.add(p(15,"增加售后单","biz:sale:add",13));
		pl.add(p(16,"修改售后单","biz:sale:mod",13));
		pl.add(p(17,"删除售后单","biz:sale:del",13));
		
		pl.add(p(18,"维修单","biz:maintain",0));
		pl.add(p(19,"查看维修单","biz:maintain:view",18));
		pl.add(p(20,"增加维修单","biz:maintain:add",18));
		pl.add(p(21,"修改维修单","biz:maintain:mod",18));
		pl.add(p(22,"删除维修单","biz:maintain:del",18));
		
		pl.add(p(23,"调律单","biz:tuning",0));
		pl.add(p(24,"查看调律单","biz:tuning:view",23));
		pl.add(p(25,"增加调律单","biz:tuning:add",23));
		pl.add(p(26,"修改调律单","biz:tuning:mod",23));
		pl.add(p(27,"删除调律单","biz:tuning:del",23));
		
		pl.add(p(28,"售后回访记录","biz:saleReturn",0));
		pl.add(p(29,"查看售后回访记录","biz:saleReturn:view",28));
		pl.add(p(30,"增加售后回访记录","biz:saleReturn:add",28));
		pl.add(p(31,"修改售后回访记录","biz:saleReturn:mod",28));
		pl.add(p(32,"删除售后回访记录","biz:saleReturn:del",28));
		
		pl.add(p(33,"客户信息","biz:customer",0));
		pl.add(p(34,"查看客户信息","biz:customer:view",33));
		pl.add(p(35,"增加客户信息","biz:customer:add",33));
		pl.add(p(36,"修改客户信息","biz:customer:mod",33));
		pl.add(p(37,"删除客户信息","biz:customer:del",33));
		
		pl.add(p(38,"客户来访记录","biz:customerVisit",0));
		pl.add(p(39,"查看客户来访记录","biz:customerVisit:view",38));
		pl.add(p(40,"增加客户来访记录","biz:customerVisit:add",38));
		pl.add(p(41,"修改客户来访记录","biz:customerVisit:mod",38));
		pl.add(p(42,"删除客户来访记录","biz:customerVisit:del",38));
		
		pl.add(p(43,"合作方信息","biz:institution",0));
		pl.add(p(44,"查看合作方信息","biz:institution:view",43));
		pl.add(p(45,"增加合作方信息","biz:institution:add",43));
		pl.add(p(46,"修改合作方信息","biz:institution:mod",43));
		pl.add(p(47,"删除合作方信息","biz:institution:del",43));
		
		pl.add(p(48,"合作方回访记录","biz:institutionReturn",0));
		pl.add(p(49,"查看合作方回访记录","biz:institutionReturn:view",48));
		pl.add(p(50,"增加合作方回访记录","biz:institutionReturn:add",48));
		pl.add(p(51,"修改合作方回访记录","biz:institutionReturn:mod",48));
		pl.add(p(52,"删除合作方回访记录","biz:institutionReturn:del",48));
		
		pl.add(p(53,"厂商信息","biz:producer",0));
		pl.add(p(54,"查看厂商信息","biz:producer:view",53));
		pl.add(p(55,"增加厂商信息","biz:producer:add",53));
		pl.add(p(56,"修改厂商信息","biz:producer:mod",53));
		pl.add(p(57,"删除厂商信息","biz:producer:del",53));
		
		pl.add(p(58,"产品型号","biz:product",0));
		pl.add(p(59,"查看产品型号","biz:product:view",58));
		pl.add(p(60,"增加产品型号","biz:product:add",58));
		pl.add(p(61,"修改产品型号","biz:product:mod",58));
		pl.add(p(62,"删除产品型号","biz:product:del",58));
		
		pl.add(p(63,"员工信息","biz:staff",0));
		pl.add(p(64,"查看员工信息","biz:staff:view",63));
		pl.add(p(65,"增加员工信息","biz:staff:add",63));
		pl.add(p(66,"修改员工信息","biz:staff:mod",63));
		pl.add(p(67,"删除员工信息","biz:staff:del",63));
		return pl;
	}
	
	private static Permission p(Integer id,String name,String code,Integer pid) {
		Permission  p = new Permission();
		p.setId(id);
		p.setParentId(pid);
		p.setTitle(name);
		p.setCode(code);
		return p;
	}
}
